package com.kma.summer2012.client.view.header;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.*;
import com.kma.summer2012.client.SiteMap;
import com.kma.summer2012.client.constants.ConstantsPresenter;
import com.kma.summer2012.client.presenters.breadcrumbs.BreadCrumbsPresenter;
import com.kma.summer2012.client.presenters.header.HeaderPresenter;
import com.kma.summer2012.client.styles.style2.Recources;
import com.kma.summer2012.client.view.breadCrumbs.BreadCrumbs;

public class Header extends Composite implements HeaderPresenter.Display {

    interface CurrentUserUiBinder extends UiBinder<Widget, Header> {
    }

    private static CurrentUserUiBinder ourUiBinder = GWT.create(CurrentUserUiBinder.class);

    @UiField
    protected Label nameUser;

    @UiField
    protected Label positionUser;

    @UiField
    protected Button logOut;

    @UiField
    protected BreadCrumbs breadCrumbs;

    public static ConstantsPresenter c;

    public void useConstants() {
        c = GWT.create(ConstantsPresenter.class);

    }

    public Header() {
        useConstants();
        HTMLPanel rootElement = (HTMLPanel) ourUiBinder.createAndBindUi(this);
        RootPanel.get(c.HEADER()).addStyleName(Recources.INSTANCE.styles().header());
        logOut.addStyleName(Recources.INSTANCE.styles().Caption());
        initWidget(rootElement);

        (new BreadCrumbsPresenter(this.breadCrumbs)).go(rootElement);
        this.breadCrumbs.setPath(SiteMap.getInstance().getPath(History.getToken()));
    }

    @Override
    public HasClickHandlers getLogOutButton() {
        return logOut;
    }

    @Override
    public void setPosition(String position) {
        this.positionUser.setText(position);
    }

    @Override
    public void setName(String name) {
        nameUser.setText(name);
    }

    @Override
    public Widget asWidget() {
        return this;
    }
}